using System;
using UnityEngine;

public class StartUI : MonoBehaviour
{
    private GameObject uiobj;

    public UILabel titlename;

    public UISprite[] bigstar;

    public UISprite[] smallstar;

    public UILabel[] starinfo;

    public UIEventListener startbtn;

    public UILabel energylabel;

    public UILabel explabel;

    public UILabel moneylabel;

    public GameObject[] getobj;

    public Piece_item[] getpieceitem;

    private level_info curlevelinfo;

    private int levelnum;

    private int islevelfirst;

    private void Start()
    {
        UIEventListener uIEventListener = startbtn;
        uIEventListener.onClick = (UIEventListener.VoidDelegate)Delegate.Combine(uIEventListener.onClick, new UIEventListener.VoidDelegate(OnClickstartBtn));
    }

    public void init_ui_info(int num)
    {
        levelnum = num;
        MenuPlayerprefs.instance.readAllLevel();
        islevelfirst = MenuPlayerprefs.instance.getlevel_first(num);
        int num2 = MenuPlayerprefs.instance.levelstar[num];
        int num3 = 0;
        for (int i = 0; i < 3; i++)
        {
            if (num2 % 10 != 0)
            {
                num3++;
                smallstar[i].enabled = true;
            }
            else
            {
                smallstar[i].enabled = false;
            }
            num2 /= 10;
        }
        for (int j = 0; j < 3; j++)
        {
            if (j < num3)
            {
                bigstar[j].enabled = true;
            }
            else
            {
                bigstar[j].enabled = false;
            }
        }
        curlevelinfo = MenuDataController.instance.levelinfo[num];
        LevelStar levelStar = new LevelStar();
        for (int k = 0; k < 3; k++)
        {
            levelStar = MenuDataController.instance.starinfo[curlevelinfo.starid[k]];
            starinfo[k].text = k + 1 + ". ";
            switch (levelStar.type)
            {
                case 1:
                    starinfo[k].text += "完成关卡";
                    break;
                case 2:
                    {
                        UILabel obj2 = starinfo[k];
                        string text = obj2.text;
                        obj2.text = text + "至少 " + levelStar.sontype + "% 血量";
                        break;
                    }
                case 3:
                    switch (levelStar.sontype)
                    {
                        case 0:
                            starinfo[k].text += "击败所有敌人";
                            break;
                        case 1:
                            starinfo[k].text += "击落所有战斗机";
                            break;
                        case 2:
                            starinfo[k].text += "摧毁所有建筑";
                            break;
                        case 3:
                            starinfo[k].text += "击沉所有战舰";
                            break;
                    }
                    break;
                case 4:
                    switch (levelStar.sontype)
                    {
                        case 0:
                            starinfo[k].text += "保护所有友方单位";
                            break;
                        case 1:
                            starinfo[k].text += "保护所有友方战斗机";
                            break;
                        case 2:
                            starinfo[k].text += "保护所有友方建筑";
                            break;
                        case 3:
                            starinfo[k].text += "保护所有友方战舰";
                            break;
                    }
                    break;
                case 5:
                    {
                        UILabel obj = starinfo[k];
                        string text = obj.text;
                        obj.text = text + "在 " + levelStar.sontype / 60 + " 分钟内完成关卡";
                        break;
                    }
                case 6:
                    starinfo[k].text += "潜在任务成功";
                    break;
                case 7:
                    starinfo[k].text += "成功完成速度竞赛";
                    break;
            }
        }
        energylabel.text = "-" + curlevelinfo.energy;
        explabel.text = string.Empty + curlevelinfo.success_exp;
        moneylabel.text = string.Empty + curlevelinfo.success_gold;
        titlename.text = "关卡" + (num / 6 + 1) + "-" + (num % 6 + 1);
        for (int l = 0; l < 2; l++)
        {
            if (curlevelinfo.dropitem[l].dropid != -1)
            {
                PieceData pd = MenuDataController.instance.Getdroppiece(curlevelinfo.dropitem[l].dropid);
                getpieceitem[l].enable(pd);
            }
            else
            {
                NGUITools.SetActive(getobj[l], state: false);
            }
        }
    }

    public void OnClickstartBtn(GameObject btn)
    {
        if (MenuPlayerprefs.instance.DecEnergy(curlevelinfo.energy))
        {
            if (!AdManager1.instance.ShieldAddress) CheckTouch.Show();
            startScene();
        }
        else
        {
            MonoInstance<AudioController>.instance.play(AudioType.UI_BTN1, 0f);
            MenuUIController.instance.enable_chargeui(2);
        }
    }

    private void startScene()
    {
        if (islevelfirst == 1)
        {
            Platform.flurryEvent_level(levelnum, 0);
            MenuPlayerprefs.instance.SetLevel_first(levelnum);
        }
        Platform.flurryEvent_level(levelnum, 1);
        GlobalInf.gamemode = TASKMODE.level;
        GlobalInf.CurrentLevel = levelnum;
        MenuUIController.instance.nextscene();
    }

    public void enable(int curlv)
    {
        if (uiobj == null)
        {
            uiobj = base.gameObject;
        }
        NGUITools.SetActive(uiobj, state: true);
        init_ui_info(curlv);
    }

    public void disable()
    {
        NGUITools.SetActive(uiobj, state: false);
    }
}
